//
//  EDSVideoPreviewBottomView.m
//  DrivieSchoolStudents
//
//  Created by TangBin on 2019/5/27.
//  Copyright © 2019 班文政. All rights reserved.
//

#import "EDSVideoPreviewBottomView.h"

@interface EDSVideoPreviewBottomView ()

@property (nonatomic, strong) UIButton *btnCrop; ///< 裁剪按钮
@property (nonatomic, strong) UIButton *btnFinished; ///< 完成

@property (nonatomic, strong) UILabel *tipLabel;

@property (nonatomic, copy) NSString *leftTitle;
@property (nonatomic, copy) NSString *rightTitle;

- (void)initWithBtnCrop;

- (void)initWithBtnFinished;

- (void)initWithTipLabel;

@end

@implementation EDSVideoPreviewBottomView

- (void)dealloc
{
    
}

- (instancetype)initWithFrame:(CGRect)frame leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle
{
    self.leftTitle = leftTitle;
    self.rightTitle = rightTitle;
    return [self initWithFrame:frame];
}

- (void)initWithVar
{
    [super initWithVar];
    
}

- (void)initWithSubView
{
    [super initWithSubView];
    
    self.backgroundColor = [UIColor colorWithHexString:@"#262625"];
    
    [self initWithBtnCrop];
    
    [self initWithBtnFinished];
    
    [self initWithTipLabel];
}

- (void)initWithBtnCrop
{
    if (!_btnCrop)
    {
        CGRect frame = CGRectMake(5, (49.0 - 30) * 0.5, 60, 30);
        _btnCrop = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnCrop.frame = frame;
        [_btnCrop setTitle:self.leftTitle forState:UIControlStateNormal];
        [_btnCrop setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btnCrop.titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:_btnCrop];
    }
}

- (void)initWithBtnFinished
{
    if (!_btnFinished)
    {
        CGRect frame = self.btnCrop.frame;
        _btnFinished = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnFinished.frame = frame;
        [_btnFinished setTitle:self.rightTitle forState:UIControlStateNormal];
        [_btnFinished setTitleColor:[UIColor colorWithHexString:@"#13ae24"] forState:UIControlStateNormal];
        _btnFinished.titleLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:_btnFinished];
        _btnFinished.right = kScreenWidth - 5;
    }
}

- (void)initWithTipLabel
{
    if (!_tipLabel)
    {
        CGRect frame = CGRectMake(_btnCrop.left + 14, 0, 150, 20);
        _tipLabel = [[UILabel alloc] initWithFrame:frame];
        _tipLabel.font = [UIFont systemFontOfSize:14];
        _tipLabel.textColor = [UIColor whiteColor];
        _tipLabel.centerY = _btnCrop.centerY;
        _tipLabel.text = [NSString stringWithFormat:@"最多可发布%d秒视频", kRECORD_VIDEO_TIME];
        [self addSubview:_tipLabel];
        _tipLabel.hidden = YES;
    }
}

/**
 传递视频的播放时长
 
 @param seconds seconds description
 */
- (void)updateVideoTime:(NSInteger)seconds
{
    if (seconds > kRECORD_VIDEO_TIME)
    {// 大于60S
        _tipLabel.hidden = NO;
        _btnFinished.hidden = YES;
        [_btnCrop setTitleColor:[UIColor colorWithHexString:@"#13ae24"] forState:UIControlStateNormal];
        _btnCrop.frame = _btnFinished.frame;
    }
    else
    {
        _tipLabel.hidden = YES;
        _btnFinished.hidden = NO;
        _btnCrop.left = 5;
        [_btnCrop setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        if (seconds <= 15)
        {// 大于15秒，才可以裁剪
            _btnCrop.hidden = YES;
        }
    }
}


@end
